<?php
namespace Modules\Category\Models;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $table = 'categories'; // 表名
    protected $fillable = ['name', 'pid', 'level', 'status', 'group']; // 可批量赋值字段

    // 基础子分类关系，不带状态过滤
    public function children()
    {
        return $this->hasMany(Category::class, 'pid', 'id'); // 外键 pid，主键 id
    }

    public function childrenRecursive()
    {
        return $this->children()->with(['childrenRecursive']);
    }
}
